package site.jlopen.utils.file;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FileUtil {
	private final static Logger logger = LoggerFactory.getLogger(FileUtil.class);
	
	public static boolean byte2File(byte[] data, String savePath, String fileName) {
		if(null == data || data.length == 0) {
			return false;
		}
		File fo = new File(savePath);
		if(!fo.exists()) {
			fo.mkdirs();
		}
		FileOutputStream fos = null;
		try {
			fos = new FileOutputStream(savePath + File.separator + fileName);
			fos.write(data,0,data.length);
			fos.flush();
			return true;
		} catch (IOException e) {
			logger.error("写入文件{}异常：{}", savePath, e);
			return false;
		} finally {
			if(null != fos) {
				try {
					fos.close();
				} catch (IOException e) {
					logger.error("写入文件{}关闭输出流异常：{}", savePath, e);
				}
			}
		}
	}
}
